#include "Animation.h"


#include "../SGD Wrappers/CSGD_Direct3D.h"
//#include "../SGD Wrappers/CSGD_TextureManager.h"

#include "AnimationManager.h"







CAnimation::CAnimation(void)
{
	
	m_pTM	= CSGD_TextureManager::GetInstance();

}


CAnimation::~CAnimation(void)
{
}

void CAnimation::Init()
{

	imageID		= m_pTM->LoadTexture( _T("Resource/Hinata.png" ) );

	 
	

	currFrame = 0;
	maxFrame = 6;
	currAnimation = 0;
	 
	FrameDuration = 0.25f;
	FrameSpeed = 2.0f;
	TimeWaited = 0.0f;
	
	isLooping  =true;
	isPlaying  =true;


}


void CAnimation::Update(float fElapsedTime)
{
		// Increase our timer
	TimeWaited += fElapsedTime * FrameSpeed;


	// Next frame?
	if(isPlaying && TimeWaited > FrameDuration )
	{
		currFrame++;
		TimeWaited = 0.0f;

		// End of the animation?
		if( currFrame >= maxFrame )
		{
			currFrame = 0;

			// Restart?
			if( isLooping == true )
			{
				currFrame++;
				isPlaying = true;
			}
			else
			{
				isPlaying = false;
				//currFrame = maxFrame -1;
			}

		}		
	}


}

void CAnimation::Render()
{

	//tFrame temp = this->frames[currFrame];
	
	int vecSize = CAnimationManager::GetInstance()->AllAnimations.size();
	vector<CAnimation*> tempAnims = CAnimationManager::GetInstance()->AllAnimations;
	tFrame* temp = CAnimationManager::GetInstance()->AllAnimations[currAnimation]->frames[currFrame];
	CAnimationManager::GetInstance()->AniObj = CAnimationManager::GetInstance()->AllAnimations[currAnimation];

	m_pTM->Draw( imageID, 250,105,1,1, &temp->m_rRenderRect);

}
